From 6b5539679458b2a6b8db6b314278728a7f7bce4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Elliott=20B=C3=A9cue?= Date: Mon, 28 Jan 2013 22:27:15 +0100 Subject: [PATCH] =?UTF-8?q?=20*=20Corrections=20pour=20que=20les=20rid=20n?= =?UTF-8?q?on=20d=C3=A9sir=C3=A9s=20ne=20soient=20pas=20pris.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- attributs.py | 46 +++++++++++++++++++++++++++++++++++----------- lc_ldap.py | 7 +++++-- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/attributs.py b/attributs.py index e6341fa..9bf13c5 100644 --- a/attributs.py +++ b/attributs.py @@ -33,13 +33,16 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import re, sys, netaddr, time +import re +import sys +import netaddr +import time from unicodedata import normalize from crans_utils import format_tel, format_mac, mailexist, validate_name, ip4_of_rid, ip6_of_mac sys.path.append("/usr/scripts/gestion") -import config, annuaires_pg -from ridtools import Rid +import config +import annuaires_pg ### Les droits # en cas de typo, l'appel d'une variable plante, on préfèrera donc les utiliser en lieu et place @@ -207,6 +210,9 @@ class aid(intAttr): can_view = [nounou, apprenti, 'Cableurs'] + def parse_value(self, val, ldif): + self.value = int(val) + class uid(Attr): singlevalue = True option = False @@ -468,8 +474,7 @@ class ip6HostNumber(Attr): can_modify = [nounou] def parse_value(self, ip, ldif): - if ip == '': - ip = ip6_of_mac(ldif['macAddress'][0], ldif['rid'][0]) + ip = ip6_of_mac(ldif['macAddress'][0], ldif['rid'][0]) self.value = netaddr.ip.IPAddress(ip) def __unicode__(self): @@ -479,28 +484,44 @@ class mid(Attr): singlevalue = True optional = False unique = True - legend = "Identifiant de machine" + legend = u"Identifiant de machine" category = 'id' def parse_value(self, mid, ldif): - self.value = mid + self.value = int(mid) def __unicode__(self): - return unicode(int(self.value)) + return unicode(self.value) class rid(Attr): singlevalue = True optional = False unique = True - legend = "Identifiant réseau de machine" + legend = u"Identifiant réseau de machine" category = 'id' can_modify = [nounou] def parse_value(self, rid, ldif): - self.value = Rid(rid = int(rid)) + rid = int(rid) + + # 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] + + for plage in plages: + if rid in plage: + if rid % 256 == 0 or rid % 256 == 255: + rid = -1 + break + else: + continue + else: + continue + + self.value = rid def __unicode__(self): - return unicode(int(self.value)) + return unicode(self.value) class ipsec(Attr): singlevalue = False @@ -587,6 +608,9 @@ class cid(intAttr): unique = True legend = u"Identifiant du club" category = 'id' + + def parse_value(self, val, ldif): + self.value = int(val) class responsable(Attr): singlevalue = True diff --git a/lc_ldap.py b/lc_ldap.py index a520e78..28322a4 100644 --- a/lc_ldap.py +++ b/lc_ldap.py @@ -60,7 +60,6 @@ import config import crans_utils from attributs import * from ldap_locks import CransLock -import ridtools uri = 'ldap://ldap.adm.crans.org/' base_dn = 'ou=data,dc=crans,dc=org' @@ -326,7 +325,11 @@ class lc_ldap(ldap.ldapobject.LDAPObject): if i in nonfree: continue else: - break + my_id = attrify(i, attr, self, True) + if my_id.value != i: + continue + else: + break else: raise EnvironmentError('Aucun %s libre dans la plage [%d, %d]' % (attr, plage[0], i))